home *** CD-ROM | disk | FTP | other *** search
/ Interactive Media Design Review 1999 / Interactive Media Design Review 1999.iso / pc / allfiles / angry / intro.dir / 00006_Script_gravity < prev    next >
Text File  |  1999-03-01  |  3KB  |  157 lines

  1. property mySpr, mass, velocity, location
  2. property timeScale, scale, systemOrigin
  3. property frozen, activated
  4. property animCount, myAnim
  5. property flyMass
  6. property pSoftSound, pHardSound
  7.  
  8.  
  9. global stageWidth, stageHeight
  10.  
  11. on new me, thisSpr, thisAnim, thisSound  
  12.   
  13.   set mySpr = thisSpr
  14.   set myAnim = thisAnim
  15.   set timeScale = 50 -- seconds per update
  16.   set scale = 5 -- units per pixel
  17.   
  18.   set pSoftSound = 0
  19.   set pHardSound = 0
  20.   
  21.   if thisSound then
  22.     set pSoftSound = thisSound
  23.     set pHardSound = thisSound + 1
  24.   end if
  25.   
  26.   
  27.   set stageWidth = the stageRight - the stageLeft
  28.   set stageHeight = the stageBottom - the stageTop
  29.   
  30.   set systemOrigin = [ #X:stageWidth/2, #Y:stageHeight/2 ]
  31.   
  32.   --  puppetSprite mySpr, TRUE
  33.   
  34.   set frozen = FALSE
  35.   set activated = FALSE
  36.   
  37.   set mass = 65
  38.   set flyMass = 100
  39.   
  40.   set velocity = [#X:0, #Y:0]
  41.   
  42.   setloc me
  43.   
  44.   return me
  45. end new
  46.  
  47.  
  48. on setloc me
  49.   set newX = (the locH of sprite(mySpr) - the X of systemOrigin) * scale
  50.   set newY = (the locV of sprite(mySpr) - the Y of systemOrigin) * scale
  51.   
  52.   set location = [#X:newX, #Y:newY]
  53. end setloc
  54.  
  55.  
  56. on gravitate me
  57.   
  58.   set mouseMass = mass / 2
  59.   set flyMouseMass = flyMass / 4
  60.   --------
  61.   
  62.   if mySpr = 12 then
  63.     set N = flyGravity(mySpr, FlyMass, point(the mouseH, the mouseV),¼
  64.                      flyMouseMass, 0, "attract") -- the mouse
  65.   else
  66.     set N = calcGravity(mySpr, mass) -- jean paul's
  67.   end if
  68.   
  69.   push me, N
  70.   
  71. end gravitate
  72.  
  73.  
  74. on push me, theForce
  75.   
  76.   set acceleration = theForce / mass
  77.   
  78.   set deltaVelocity = acceleration * timeScale
  79.   
  80.   set velocity = velocity + deltaVelocity
  81.   
  82.   -- bounce
  83.   
  84.   set playSound = FALSE
  85.   
  86.   if the bottom of sprite(mySpr) > stageHeight then
  87.     if the Y of velocity > 0 then
  88.       set the Y of velocity to - the Y of velocity
  89.       set playSound = TRUE
  90.     end if
  91.   end if
  92.   
  93.   if the top of sprite(mySpr) < 0 then
  94.     if the Y of velocity < 0 then
  95.       set the Y of velocity to - the Y of velocity
  96.       set playSound = TRUE
  97.     end if
  98.   end if  
  99.   
  100.   if the left of sprite(mySpr) < 0 then
  101.     if the X of velocity < 0 then
  102.       set the X of velocity to - the X of velocity
  103.       set playSound = TRUE
  104.     end if
  105.   end if
  106.   
  107.   if the right of sprite(mySpr) > stageWidth then
  108.     if the X of velocity > 0 then
  109.       set the X of velocity to - the X of velocity
  110.       set playSound = TRUE
  111.     end if
  112.   end if
  113.   
  114.   if playSound AND pSoftSound AND random(2) = 2 then
  115.     
  116.     set maxVeloc = max(abs(the X of velocity), abs(the Y of velocity))
  117.     
  118.     if maxVeloc > 300 then puppetSound 2, pHardSound
  119.     else puppetSound 2, pSoftSound
  120.     
  121.   end if
  122.     
  123.   move me
  124.   
  125. end push
  126.  
  127.  
  128. on move me
  129.   
  130.   set location = location + velocity
  131.   
  132.   set newLocH = the X of systemOrigin + (integer(the X of location) / scale)
  133.   set newLocV = the Y of systemOrigin + (integer(the Y of location) / scale)
  134.   
  135.   set the locH of sprite(mySpr) = newLocH
  136.   set the locV of sprite(mySpr) = newLocV
  137.   
  138. end move
  139.  
  140.  
  141. on animLoop me   -- art animation
  142.   
  143.   
  144.   if animCount <> count(myAnim) then
  145.     set animCount = animCount + 1
  146.     if animCount >= count(myAnim) then
  147.       set animCount = count(myAnim)      
  148.     end if
  149.     set the member of sprite(mySpr) = member getAt(myAnim, animCount)
  150.   else if animCount = count(myAnim) then
  151.     set animCount = 0
  152.     
  153.   end if
  154.   
  155. end animLoop
  156.  
  157.